<template>
  <view class="index">
    <view class="jtop">
      <view class="status_bar"><!-- 这里是状态栏 --></view>
      <!-- <view class="jtop_l" @tap="navigateBack"><image src="../../static/img/ic_back.png"></image></view> -->
      <view class="jtop_l" @tap="navigateBack">取消</view>
      <view class="jtop_c">编辑成员</view>
      <view class="jtop_r" :class="duty ? '' : 'no'" @click="jsave">保存</view>
    </view>
    <view class="tophr"></view>

    <view class="ubs">
      <view class="ub">
        <view class="ub_l">公司</view>
        <!-- <image src="../../static/img/user/ic_right.png" class="ub_jt"></image> -->
        <view class="ub_t">{{ realname }}</view>
      </view>
      <view class="ub">
        <view class="ub_l">职位</view>
        <!-- <image src="../../static/img/user/ic_right.png" class="ub_jt"></image> -->
        <input
          type="text"
          placeholder="请输入职位"
          :value="duty"
          @input="onKeyInput"
          class="ub_t"
        />
        <!-- <view >总经理</view> -->
      </view>
    </view>

    <view class="ubs ubs2" @click="jdelete">
      删除成员
    </view>
  </view>
</template>

<script>
import request from '@/common/request.js';
import { mapState, mapMutations } from 'vuex';

export default {
  computed: {
    ...mapState(['hasLogin', 'forcedLogin']),
  },
  data() {
    return {
      repeat_click: true,
      ashowpop: false,
      duty: '',
      id: '',
      realname: '',
      user: {},
    };
  },
  onLoad(e) {
    console.log(e);

    this.id = e.id;
    this.realname = e.realname;

    if (e.duty != 'undefined') {
      this.duty = e.duty;
    }
  },
  methods: {
    onKeyInput: function(event) {
      this.duty = event.detail.value;
    },
    jsave() {
      if (!this.repeat_click) {
        return;
      }
      this.repeat_click = false;
      if (!this.duty) {
        this.repeat_click = true;
        uni.showToast({
          title: '请输入职位',
          icon: 'none',
        });
        return;
      }

      request({
        url: '/ucenter/corp-user/' + this.id,
        data: {
          duty: this.duty,
        },

        method: 'PUT',
        success: openIdRes => {
          console.log(openIdRes);
          if (openIdRes.data.success == true) {
            this.repeat_click = true;
            uni.showToast({
              title: '修改成功',
            });
            // uni.navigateBack()
          } else {
            this.repeat_click = true;
            uni.showToast({
              title: openIdRes.data.msg,
              icon: 'none',
            });
            this.isLoading = false;
          }
        },
        fail: () => {
          this.repeat_click = true;
          uni.showToast({
            title: '服务器开小差，请稍后~',
            icon: 'none',
          });
          return false;
        },
      });
    },

    jdelete() {
      var aa = this.id;
      request({
        url: '/ucenter/corp-user/' + aa,
        method: 'DELETE',

        success: res => {
          if (res.data.success == true) {
            wx.showToast({
              title: '删除成功',
              icon: 'none',
              duration: 1500,
              success: function() {
                setTimeout(function() {
                  uni.navigateTo({
                    url: '../user/tream',
                  });
                }, 1500);
              },
            });
          } else {
            // 错误
            this.repeat_click = true;
            uni.showToast({
              title: res.data.msg,
              icon: 'none',
            });
          }
        },
        fail: () => {
          this.repeat_click = true;
          uni.showToast({
            title: '服务器开小差，请稍后~',
            icon: 'none',
          });
          return false;
        },
      });
    },
    user_edit_company() {
      uni.navigateTo({
        url: '../user/user_edit_company',
      });
    },
    user_edit_mail() {
      uni.navigateTo({
        url: '../user/user_edit_mail',
      });
    },
    user_edit_phone() {
      uni.navigateTo({
        url: '../user/user_edit_phone',
      });
    },
    user_edit_sex() {
      uni.navigateTo({
        url: '../user/user_edit_sex',
      });
    },
    user_edit_name() {
      uni.navigateTo({
        url: '../user/user_edit_name',
      });
    },
    user_head() {
      uni.navigateTo({
        url: '../user/user_head',
      });
    },
    bindLogin() {
      uni.navigateTo({
        url: '../login/login',
      });
    },
    bindLogout() {
      this.logout();
      /**
       * 如果需要强制登录跳转回登录页面
       */
      if (this.forcedLogin) {
        uni.reLaunch({
          url: '../login/login',
        });
      }
    },
    navigateBack() {
      uni.navigateBack();
    },
  },
};
</script>

<style>
.ubs {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  margin: 20rpx 0 0 0;
  border: 1px solid #dddddd;
  border-left: 0;
  border-right: 0;
  background: #ffffff;
}
.ubs2 {
  text-align: center;
  color: #eb5342;
  font-size: 36rpx;
  line-height: 90rpx;
}
.ub {
  width: 720rpx;
  height: 90rpx;
  display: block;
  float: right;
  line-height: 90rpx;
  border-bottom: 1px solid #dddddd;
}
.ubs .ub:last-child {
  border: 0;
}
.ub_l {
  width: auto;
  height: auto;
  display: block;
  float: left;
  font-size: 34rpx;
  line-height: 90rpx;
  color: #000000;
  margin: 0rpx 0 0 0;
}
.ub_jt {
  width: 16rpx;
  height: 25rpx;
  display: block;
  float: right;
  margin: 32rpx 30rpx 0 0;
}
.ub_t {
  width: auto;
  height: 40rpx;
  display: block;
  float: right;
  font-size: 32rpx;
  line-height: 40rpx;
  text-align: right;
  color: #999999;
  margin: 25rpx 20rpx 0 0;
}
.ub_t image {
  width: 36rpx;
  height: 36rpx;
  display: block;
  float: right;
  margin: 0rpx 0rpx 0 6rpx;
}
.ub_tx {
  width: 114rpx;
  height: 114rpx;
  display: block;
  float: right;
  margin: 30rpx 20rpx 30rpx 0;
  border-radius: 8rpx;
}
.uba {
  height: auto;
}
.uba .ub_l {
  margin-top: 45rpx;
}
.uba .ub_jt {
  margin-top: 75rpx;
}

.index {
  background: rgb(242, 242, 242);
  width: 100%;
  height: auto;
}
.jtop {
  width: 100%;
  height: 88rpx;
  background: #ffffff;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
  box-shadow: inset 0px -1px 0px #dddddd;
}
.jtop_l {
  width: auto;
  height: 88rpx;
  display: block;
  float: left;
  font-size: 32rpx;
  color: #000000;
  line-height: 88rpx;
  margin: 0 0 0 30rpx;
}
.jtop_r {
  width: auto;
  height: 88rpx;
  display: block;
  float: right;
  margin: 0rpx 20rpx 0 0;
  line-height: 88rpx;
  font-size: 32rpx;
  color: #000000;
  color: #256aff;
}
.jtop_r.no {
  opacity: 0.5;
}
.jtop_r image {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
}

.jtop_lt {
  margin: 0 0 0 10rpx;
}
/* .jtop_r{width: 48rpx; height: 48rpx; display: block;float: right; margin: 20rpx 20rpx 0 0;} */
/* .jtop_rl{margin: 20rpx 30rpx 0 0;} */
/* .jtop_r image{width: 48rpx; height: 48rpx; display: block;float: left;} */
.jtop_c {
  width: 70%;
  height: 48rpx;
  line-height: 48rpx;
  display: block;
  float: left;
  position: fixed;
  top: 20rpx;
  left: 15%;
  text-align: center;
  font-size: 36rpx;
  color: #000000;
}
.jtop_c image {
  width: 36rpx;
  height: 36rpx;
  display: inline-block;
  float: none;
  margin-bottom: -5rpx;
  margin-left: 5rpx;
}
.jtop_b {
  width: 100%;
  height: auto;
  background: #ffffff;
  position: fixed;
  top: 88rpx;
  left: 0;
  z-index: 1001;
}
.tophr {
  width: 100%;
  height: 88rpx;
}

input {
  width: auto;
  height: 50rpx;
  display: block;
  float: right;
  margin: 20rpx 30rpx 0 0;
  text-align: right;
  line-height: 50rpx;
  font-size: 34rpx;
  color: #999999;
}
</style>
